package zmee.pur.src.opplugin;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.args.AfterOperationArgs;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: xw
 * @Date: 2023/03/06/15:37
 * @Description: 开标准备反审核时将资质后审.资质后审设置的资审人员清空
 */
public class BidOpenUnAuditOp extends AbstractOperationServicePlugIn {

    @Override
    public void afterExecuteOperationTransaction(AfterOperationArgs e) {
        super.afterExecuteOperationTransaction(e);
        DynamicObject[] dataEntities = e.getDataEntities();
        for (DynamicObject dataEntity : dataEntities) {
            Object id = dataEntity.get("id");
            QFilter filter = new QFilter("parentid", QCP.equals, id);
            DynamicObject aptidudeConfig = BusinessDataServiceHelper.loadSingle("src_aptitudeconfig2", "entryentity.scorer",
                    filter.toArray());
            if (aptidudeConfig != null) {
                DynamicObjectCollection entryEntity = aptidudeConfig.getDynamicObjectCollection("entryentity");
                entryEntity.get(0).set("scorer", null);
                SaveServiceHelper.save(new DynamicObject[]{aptidudeConfig});
            }
        }
    }
}
